package com.zzyl.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.zzyl.dto.BedDto;
import com.zzyl.entity.Bed;
import com.zzyl.mapper.BedMapper;
import com.zzyl.service.BedService;
import com.zzyl.vo.BedVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class BedServiceImpl implements BedService {


    @Autowired
    private BedMapper bedMapper;

    @Override
    public List<BedVo> getBedsByRoomId(Long roomId) {
        return bedMapper.getBedsByRoomId(roomId);
    }
    @Override
    public void createBed(BedDto bedDto) {
        Bed bean = BeanUtil.toBean(bedDto, Bed.class);
        bean.setCreateBy(1L); // todo 获取当前用户id
        bean.setCreateTime(LocalDateTime.now());
        bean.setBedStatus(0); // todo 修改装套
        bedMapper.createBed(bean);
    }

    @Override
    public BedVo getBedById(Long id) {
        return bedMapper.getBedById(id);
    }

    @Override
    public void updateBed(BedDto bedDto) {
        bedMapper.updateBed(BeanUtil.toBean(bedDto, Bed.class));
    }

    @Override
    public void deleteBedById(Long id) {
        bedMapper.deleteBedById(id);
    }

}

